<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<html>
<head>
    <title>花卉列表</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-4">
        <h2>花卉列表</h2>
        <div class="mb-3">
            <a href="${pageContext.request.contextPath}/flower/add" class="btn btn-primary">添加花卉</a>
            <a href="${pageContext.request.contextPath}/flower/orders" class="btn btn-info">订单管理</a>
        </div>
        
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>名称</th>
                    <th>价格</th>
                    <th>库存</th>
                    <th>描述</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${flowers}" var="flower">
                    <tr>
                        <td>${flower.id}</td>
                        <td>${flower.name}</td>
                        <td>${flower.price}</td>
                        <td>${flower.stock}</td>
                        <td>${flower.description}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/flower/edit/${flower.id}" class="btn btn-sm btn-warning">编辑</a>
                            <button onclick="deleteFlower(${flower.id})" class="btn btn-sm btn-danger">删除</button>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script>
        function deleteFlower(id) {
            if (confirm('确定要删除这个花卉吗？')) {
                $.ajax({
                    url: '${pageContext.request.contextPath}/flower/delete/' + id,
                    type: 'DELETE',
                    success: function() {
                        location.reload();
                    }
                });
            }
        }
    </script>
</body>
</html> 